<?php
//require section
require_once dirname(__FILE__) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_news.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_multi_level.php';
require_once DOCUMENT_ROOT . DIR_INCLUDE . 'usable_functions.php';
$title = 'Chi tiết tin Tức';

if (!empty($_GET['news_id'])) {
    $news_id = $_GET['news_id'];
    $news = api_news::get_news_by_id($news_id);
}

?>

<!DOCTYPE html>
<html>
    <head>
        <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
        ?>
    </head>
    <body>
        <div class="uk-container uk-container-center uk-margin-top">
            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php';
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php';
            ?>

            <section id="main-content" class="ts-body-container">

                    <div class="ts-left-wrapper">
                        <section class="uk-panel uk-panel-box ts-padding-large">
                            <?php
                            if (empty($_GET['news_id'])) {
                                echo "<h2>Không tìm thấy tin tức này.</h2>";
                            } else {
                                $news_id = $_GET['news_id'];
                                $news = api_news::get_news_by_id($news_id);
                            ?>
                            <article class="uk-article">
                                <h1 class="uk-article-title ts-color-primary"><?php echo $news['news_title']; ?></h1>
                                <?php
                                $date = date_create($news["news_added_date"]);
                                $date_str = date_format($date, "d/m/Y H:i");
                                ?>
                                <p class="uk-article-meta">Ngày viết: <?php echo $date_str; ?></p>
                                <hr class="uk-article-divider">
                                <div>
                                    <?php echo $news['news_content']; ?>
                                </div>
                            </article>
                            <?php
                            }
                            ?>
                        </section>
                    </div>

                <script type="text/javascript">
                    function filldata(value) {
                        $.ajax({
                            type: "GET",
                            url: "<?php echo LINK_ROOT . DIR_AJAX; ?>news_folder_category.php",
                            data: "category_choosen_id=" + value,
                            success: function(result) {
                                $("#category-list").html(result);
                            }
                        });
                    }
                </script>
                <div class="ts-right-wrapper">
                    <div class="uk-panel uk-margin-bottom">
                        <div class="ts-category-title"><i class="uk-icon-list-ul"></i> Danh mục tin tức</div>
                        <ul id="category-list" class="ts-category-list">
                            <?php
                            show_news_root_list();
                            ?>
                        </ul>
                    </div>

                    <div class="uk-panel uk-margin-bottom">
                        <div class="ts-category-title"><i class="uk-icon-bolt"></i> Tin tức mới nhất</div>
                        <div class="ts-category-content">
                            <?php
                            latest_news(5);
                            ?>
                        </div>
                    </div>
                </div>
            </section>

            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
            ?>
        </div>
    </body>
</html>